﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FrameWork.web.Code;
using FrameWork.Entity;
using FrameWork.Components;

namespace FrameWork.web.Module.ITMS.Service.PromotersRegister
{
    public partial class PromotersRegister : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                sys_UserTable ut = BusinessFacade.sys_UserDisp(Common.Get_UserID);
                this.labUSERNAME.Text = ut.U_CName;
                this.labUSERNO.Text = ut.U_UserNO;

                bindPromotersRegister();
            }
        }
        /// <summary>
        /// 绑定交接班信息
        /// </summary>
        private void bindPromotersRegister()
        {
            AllSeach _AllSeach = new AllSeach();
            //DataSet ds = _AllSeach.SupesoftPage("its_PromotersRegister", "*", this.PUPromotersRegister.CurrentPageIndex, this.PUPromotersRegister.PageSize, "where 1=1", "BeginTime", "1");

            DataSet ds = _AllSeach.SupesoftPage("its_PromotersRegister", "*", this.PUPromotersRegister.PageSize, this.PUPromotersRegister.CurrentPageIndex, "where 1=1", "BeginTime", "1");

            this.GVPromotersRegister.DataSource = ds.Tables[0];
            this.GVPromotersRegister.DataBind();
            this.PUPromotersRegister.RecordCount = int.Parse(ds.Tables[1].Rows[0]["RecordCount"].ToString());

        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            
            string strMeg = "";
            if (this.txtBeginTime.Text.Trim() == "")
            {
                strMeg += "请填写开始时间！\\n";
            }
            if (txtVisitor.Text.Trim() == "")
            {
                strMeg += "请填写来访人员！\\n";
            }
            if (this.txtFinishTime.Text.Trim() == "")
            {
                strMeg += "请填写结束时间！\\n";
            }
            if (this.txtReception.Text.Trim() == "")
            {
                strMeg += "请填写接待人员！\\n";
            }
            if (strMeg != "")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "NoDate", "<script>alert('"+strMeg+"');</script>");
                return;
            }
            its_PromotersRegister _its_PromotersRegister = new its_PromotersRegister();
            _its_PromotersRegister.BeginTime = DateTime.Parse(this.txtBeginTime.Text.Trim());
            _its_PromotersRegister.Company = this.txtCompany.Text.Trim();
            _its_PromotersRegister.Visitor = this.txtVisitor.Text.Trim();
            _its_PromotersRegister.Operate = this.txtOperate.Text.Trim();
            _its_PromotersRegister.LoginType = this.txtLoginType.Text.Trim();
            _its_PromotersRegister.Influence = this.txtInfluence.Text.Trim();
            _its_PromotersRegister.FinishTime = DateTime.Parse(this.txtFinishTime.Text.Trim());
            _its_PromotersRegister.Reception = this.txtReception.Text.Trim();
            _its_PromotersRegister.USERNO = this.labUSERNO.Text;
            //_its_PromotersRegister.USERName = this.labEditUSERNAME.Text;
            _its_PromotersRegister.USERName = this.labUSERNAME.Text; 
            its_PromotersRegisterCs _its_PromotersRegisterCs = new its_PromotersRegisterCs();
            _its_PromotersRegisterCs.PromotersRegister_Create(_its_PromotersRegister);
            EventMessage.MessageBox(1, "保存成功", "保存成功!", Icon_Type.OK, this.Request.Url.ToString());
            try
            {

                bindPromotersRegister();
            }
            catch (Exception ex)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('保存失败，请联系管理员！');</script>");
                FileTxtLogs.WriteLog(ex.Message);
            }
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            //foreach (GridViewRow gr in this.GVReliefInfo.Rows)
            //{

            //    if (int.Parse(((Label)gr.FindControl("labUID")).Text) == int.Parse(this.txtEditUID.Text))
            //    {
            //        labEditUSERNO.Text = ((HyperLink)gr.FindControl("labUSERNO")).Text;
            //        labEditUSERNAME.Text = ((HyperLink)gr.FindControl("labUSERNAME")).Text;
            //        rdbEditRELIEFNO.SelectedValue = ((Label)gr.FindControl("labRELIEFNO")).Text;
            //        txtEditRELIEFDAT.Text = ((Label)gr.FindControl("labRELIEFDAT")).Text.Replace("年", "-").Replace("月", "-").Replace("日", "");
            //        labEditFILLINDAT.Text = ((Label)gr.FindControl("labFILLINDAT")).Text.Replace("年", "-").Replace("月", "-").Replace("日", "");
            //        txtEditCONTENT.Text = ((Label)gr.FindControl("labCONTENT")).Text;
            //        if (labEditUSERNO.Text.Trim() != this.labUSERNO.Text.Trim())
            //        {
            //            btnEditSave.Enabled = false;
            //        }
            //        else
            //        {
            //            btnEditSave.Enabled = true;
            //        }
            //        break;
            //    }
            //}
            //this.ClientScript.RegisterStartupScript(this.GetType(), "Edit", "<script>showTabEdit();</script>");




            foreach (GridViewRow gr in this.GVPromotersRegister.Rows)
            {

                if (int.Parse(((Label)gr.FindControl("labUID")).Text) == int.Parse(this.txtEditUID.Text))
                {
                    labEditUSERNO.Text = ((HyperLink)gr.FindControl("labItemUSERNO")).Text;
                    labEditUSERNAME.Text = ((HyperLink)gr.FindControl("labUSERNAME")).Text;
                    //rdbEditRELIEFNO.SelectedValue = ((Label)gr.FindControl("labRELIEFNO")).Text;
                    //txtEditRELIEFDAT.Text = ((Label)gr.FindControl("labRELIEFDAT")).Text.Replace("年", "-").Replace("月", "-").Replace("日", "");
                    //labEditFILLINDAT.Text = ((Label)gr.FindControl("labFILLINDAT")).Text.Replace("年", "-").Replace("月", "-").Replace("日", "");
                    //txtEditCONTENT.Text = ((Label)gr.FindControl("labCONTENT")).Text;


                    txtEditBeginTime.Text =((Label)gr.FindControl("labBeginTime")).Text;
                    txtEditCompany.Text = ((Label)gr.FindControl("labCompany")).Text;
                    txtEditVisitor.Text = ((Label)gr.FindControl("labVisitor")).Text;
                    txtEditOperate.Text = ((Label)gr.FindControl("labOperate")).Text;
                    txtEditLoginType.Text = ((Label)gr.FindControl("labLoginType")).Text;
                    txtEditInfluence.Text = ((Label)gr.FindControl("labInfluence")).Text;
                    txtEditFinishTime.Text = ((Label)gr.FindControl("labFinishTime")).Text;
                    txtEditReception.Text = ((Label)gr.FindControl("labReception")).Text;


                    if (labEditUSERNO.Text.Trim() != this.labUSERNO.Text.Trim())
                    {
                        btnEditSave.Enabled = false;
                    }
                    else
                    {
                        btnEditSave.Enabled = true;
                    }
                    break;
                }
            }
            this.ClientScript.RegisterStartupScript(this.GetType(), "Edit", "<script>showTabEdit();</script>");
        }

        protected void PUReliefInfo_PageChanged(object sender, EventArgs e)
        {
            bindPromotersRegister();
        }

        protected void btnEditSave_Click(object sender, EventArgs e)
        {
            string strMeg = "";
            if (this.txtEditBeginTime.Text.Trim() == "")
            {
                strMeg += "请填写开始时间！\\n";
            }
            if (txtEditVisitor.Text.Trim() == "")
            {
                strMeg += "请填写来访人员！\\n";
            }
            if (this.txtEditFinishTime.Text.Trim() == "")
            {
                strMeg += "请填写结束时间！\\n";
            }
            if (this.txtEditReception.Text.Trim() == "")
            {
                strMeg += "请填写接待人员！\\n";
            }
            if (strMeg != "")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "NoDate", "<script>alert('" + strMeg + "');showTabEdit()</script>");
                return;
            }
            its_PromotersRegister _its_PromotersRegister = new its_PromotersRegister();
            _its_PromotersRegister.ID = int.Parse(this.txtEditUID.Text.Trim());
            _its_PromotersRegister.BeginTime = DateTime.Parse(this.txtEditBeginTime.Text.Trim());
            _its_PromotersRegister.Company = this.txtEditCompany.Text.Trim();
            _its_PromotersRegister.Visitor = this.txtEditVisitor.Text.Trim();
            _its_PromotersRegister.Operate = this.txtEditOperate.Text.Trim();
            _its_PromotersRegister.LoginType = this.txtEditLoginType.Text.Trim();
            _its_PromotersRegister.Influence = this.txtEditInfluence.Text.Trim();
            _its_PromotersRegister.FinishTime = DateTime.Parse(this.txtEditFinishTime.Text.Trim());
            _its_PromotersRegister.Reception = this.txtEditReception.Text.Trim();
            _its_PromotersRegister.USERNO = this.labEditUSERNO.Text;
            _its_PromotersRegister.USERName = this.labEditUSERNAME.Text;
            its_PromotersRegisterCs _its_PromotersRegisterCs = new its_PromotersRegisterCs();
            _its_PromotersRegisterCs.PromotersRegister_Update(_its_PromotersRegister);
            EventMessage.MessageBox(1, "保存成功", "保存成功!", Icon_Type.OK, this.Request.Url.ToString());
            try
            {

                bindPromotersRegister();
            }
            catch (Exception ex)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('保存失败，请联系管理员！');</script>");
                FileTxtLogs.WriteLog(ex.Message);
            }
          
        }


    }
}
